package face.pay.api.wechat.service.impl;

import face.pay.dao.TerminalInfoDao;
import face.pay.entity.OrderInfo;
import face.pay.entity.TerminalInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Auther: zkj
 * @Date: 2019/9/16 15:45
 * @Description:安全校验
 */
@Component
public class AbstractOrderSafeServiceImpl {

   @Autowired
   TerminalInfoDao terminalInfoDao;


    /**
     * 支付时 安全验证
     * @param deviceId
     * @param orderInfo
     * @param totalFee
     * @param imei
     * @return
     */
    public Boolean paySafe(String deviceId, OrderInfo orderInfo, Integer totalFee,String imei){

       if(StringUtils.isNotBlank(deviceId)){

           TerminalInfo terminalInfo = this.terminalInfoDao.getByDeviceId(deviceId);

           if(terminalInfo!=null){

               Integer orderTerminalId = orderInfo.getTerminalId();

               if(orderTerminalId.equals(terminalInfo.getId())){

                   if(imei.equals(terminalInfo.getImei())){


                       if(new Long(totalFee).equals(orderInfo.getTotalFee())){
                           return true;
                       }

                   }
               }

           }

       }

        return  false;

    }

    /**
     *
     * @param deviceId
     * @param imei
     * @return 验证设备
     */
    private Boolean deviceSafe(String deviceId, String imei){

        if(StringUtils.isNotBlank(deviceId) && StringUtils.isNotBlank(imei)){

            TerminalInfo terminalInfo = this.terminalInfoDao.getByDeviceId(deviceId);
            if(imei.equals(terminalInfo.getImei())) {
                return  true;
            }

        }
        return  false;
    }
}
